import Request from "@/api/request";
import {EvevtBus} from "@/utils/EvevtBus";
import moment from "moment";
// 查询接口
export const query = (page, size, doc_status, model, view_order) => {
    return Request.get(`doc?page=${page}&size=${size}&doc_status=${doc_status}&model=${model}&view_order=${view_order}`)
};
export const getbyid = (id, model) => {
    return Request.get(`doc/getbyid?id=${id}&model=${model}`)
};
//删除接口
export const remove = (multipleSelection) => {
    return Request.post("doc/remove", multipleSelection)
};

export const upload = (model, images, data) => {
    let formData = new FormData();
    formData.append('data', JSON.stringify(data))
    formData.append('images', JSON.stringify(images))

    return Request.post(model, formData)
}

export const put = (model, images, data) => {
    let formData = new FormData();
    formData.append('data', JSON.stringify(data))
    formData.append('images', JSON.stringify(images))
    return Request.put(model, formData)
}
export const download = (id, model, title) => {
    return Request.get(`/doc/download?id=${id}&type=${model}&title=${title}`, {
        responseType: 'blob'
    })
}

export const getmodel = () => {
    Request.get("/model/modules").then(res => {
        var model = res.data.filter(item => {
            return item.id !== 27 && item.id !== 26
        })
        EvevtBus.$emit('model', model)
    })
}

export const formatDate = (row, column) => {
    let data = row[column.property]
    if (data == null) {
        return null
    }
    return moment(data).format('YYYY-MM-DD')
}
